home *** CD-ROM | disk | FTP | other *** search
/ Trusted Irix /B 4.0.4 / Trusted-Irix B-4.0.1.iso / dist / eoe1.idb / usr / include / sys / fs / nfs.h.z / nfs.h
C/C++ Source or Header  |  1992-04-03  |  13KB  |  488 lines

  1. /*    @(#)nfs.h    2.2 88/05/20 NFSSRC4.0 from  2.36 88/02/08 SMI     */
  2.  
  3. #ifndef __NFS_HEADER__
  4. #define __NFS_HEADER__
  5.  
  6. /*
  7.  * Programs are required to include rpc/types.h before this header file.
  8.  * All other prerequisites are assumed idempotent and included here.
  9.  */
  10. #include <sys/time.h>
  11. #include <sys/errno.h>
  12. #ifndef bool_t
  13. #include <rpc/xdr.h>
  14. #endif
  15.  
  16. /* Maximum size of data portion of a remote request */
  17. #define    NFS_MAXDATA    8192
  18. #define    NFS_MAXNAMLEN    255
  19. #define    NFS_MAXPATHLEN    1024
  20.  
  21. /*
  22.  * Rpc retransmission parameters
  23.  */
  24. #define    NFS_TIMEO    11    /* initial timeout in tenths of a sec. */
  25. #define    NFS_RETRIES    5    /* times to retry request */
  26.  
  27.  
  28. /*
  29.  * Error status
  30.  * Should include all possible net errors.
  31.  * For now we just cast errno into an enum nfsstat.
  32.  */
  33. enum nfsstat {
  34.     NFS_OK = 0,            /* no error */
  35.     NFSERR_PERM=EPERM,        /* Not owner */
  36.     NFSERR_NOENT=ENOENT,        /* No such file or directory */
  37.     NFSERR_IO=EIO,            /* I/O error */
  38.     NFSERR_NXIO=ENXIO,        /* No such device or address */
  39.     NFSERR_ACCES=EACCES,        /* Permission denied */
  40.     NFSERR_EXIST=EEXIST,        /* File exists */
  41.     NFSERR_NODEV=ENODEV,        /* No such device */
  42.     NFSERR_NOTDIR=ENOTDIR,        /* Not a directory */
  43.     NFSERR_ISDIR=EISDIR,        /* Is a directory */
  44.     NFSERR_FBIG=EFBIG,        /* File too large */
  45.     NFSERR_NOSPC=ENOSPC,        /* No space left on device */
  46.     NFSERR_ROFS=EROFS,        /* Read-only file system */
  47.     /*
  48.      * Alas, these errnos differ between our <sys/errno.h> and the
  49.      * Sun/BSD version, which is part of the nfs protocol!
  50.      */
  51.     NFSERR_NAMETOOLONG=63,        /* File name too long */
  52.     NFSERR_NOTEMPTY=66,        /* Directory not empty */
  53.     NFSERR_DQUOT=69,        /* Disc quota exceeded */
  54.     NFSERR_STALE=70,        /* Stale NFS file handle */
  55.     NFSERR_REMOTE=71,        /* Too many levels of remote in path */
  56.     NFSERR_WFLUSH            /* write cache flushed */
  57. };
  58. /*
  59.  * For SVR0, as with Sun, we just cast errno into an enum nfsstat.
  60.  * For SVR3 we translate.
  61.  */
  62. extern enum nfsstat    nfs_statmap[];
  63. extern short        nfs_errmap[];
  64.  
  65. #define puterrno(error) \
  66.     ((u_short)(error) > LASTERRNO ? NFSERR_IO : nfs_statmap[(short)error])
  67. #define geterrno(status) \
  68.     ((u_short)(status) > (u_short)NFSERR_WFLUSH ? (short) EIO \
  69.         : nfs_errmap[(short)status])
  70.  
  71. /*
  72.  * File types
  73.  */
  74. enum nfsftype {
  75.     NFNON = 0,
  76.     NFREG = 1,        /* regular file */
  77.     NFDIR = 2,        /* directory */
  78.     NFBLK = 3,        /* block special */
  79.     NFCHR = 4,        /* character special */
  80.     NFLNK = 5,        /* symbolic link */
  81.     NFSOCK= 6        /* named socket */
  82. };
  83.  
  84. /*
  85.  * Special kludge for fifos (named pipes)  [to adhere to NFS Protocol Spec]
  86.  *
  87.  * VFIFO is not in the protocol spec (VNON will be replaced by VFIFO)
  88.  * so the over-the-wire representation is VCHR with a '-1' device number.
  89.  *
  90.  * NOTE: This kludge becomes unnecessary with the Protocol Revision,
  91.  *       but it may be necessary to support it (backwards compatibility).
  92.  */
  93. #define NFS_FIFO_TYPE    NFCHR
  94. #define NFS_FIFO_MODE    S_IFCHR
  95. #define NFS_FIFO_DEV    (~0)
  96.  
  97. /* identify fifo in nfs attributes */
  98. #define NA_ISFIFO(NA)    (((NA)->na_type == NFS_FIFO_TYPE) && \
  99.                 ((NA)->na_rdev == NFS_FIFO_DEV))
  100.  
  101. /* set fifo in nfs attributes */
  102. #define NA_SETFIFO(NA)    { \
  103.             (NA)->na_type = NFS_FIFO_TYPE; \
  104.             (NA)->na_rdev = NFS_FIFO_DEV; \
  105.             (NA)->na_mode = ((NA)->na_mode&~S_IFMT)|NFS_FIFO_MODE; \
  106.             }
  107.  
  108.  
  109. /*
  110.  * Size of an fhandle in bytes
  111.  */
  112. #define    NFS_FHSIZE    32
  113.  
  114. /*
  115.  * File access handle
  116.  * This structure is the Sun server representation of a file.
  117.  * It is handed out by a server for the client to use in further
  118.  * file transactions.
  119.  */
  120.  
  121. #ifdef NFSSERVER
  122.  
  123. /*
  124.  * This struct is only used to find the size of the data field in the
  125.  * fhandle structure below.
  126.  */
  127. static
  128. struct fhsize {
  129.     /*
  130.      * Member f2's offset must be 0 mod 4 for NFS_FHMAXDATA to be
  131.      * an even number, given that sizeof(fsid_t) is 2.  If we institute
  132.      * a long dev_t type, then this padding must be removed.
  133.      */
  134.     u_short    f0;
  135.     fsid_t    f1;
  136.     u_short    f2;
  137.     char    f3[4];
  138.     u_short f4;
  139.     char    f5[4];
  140. };
  141. #define    NFS_FHMAXDATA    ((NFS_FHSIZE - sizeof (struct fhsize) + 8) / 2)
  142.  
  143. struct svcfh {
  144.     u_short    fh_pad;            /* make NFS_FHMAXDATA work */
  145.     fsid_t    fh_fsid;        /* filesystem id */
  146.     u_short    fh_len;            /* file number length */
  147.     char    fh_data[NFS_FHMAXDATA];    /* and data */
  148.     u_short    fh_xlen;        /* export file number length */
  149.     char    fh_xdata[NFS_FHMAXDATA];/* and data */
  150. };
  151.  
  152. typedef struct svcfh fhandle_t;
  153. #else
  154. /*
  155.  * This is the client view of an fhandle
  156.  */
  157. typedef union {
  158.     char    fh_data[NFS_FHSIZE];            /* opaque data */
  159.     u_long    fh_hash[NFS_FHSIZE/sizeof(u_long)];    /* hash key */
  160. } fhandle_t;
  161. #endif
  162.  
  163.  
  164. /*
  165.  * Arguments to remote write and writecache
  166.  */
  167. struct nfswriteargs {
  168.     fhandle_t    wa_fhandle;    /* handle for file */
  169.     u_long        wa_begoff;    /* beginning byte offset in file */
  170.     u_long        wa_offset;    /* current byte offset in file */
  171.     u_long        wa_totcount;    /* total write cnt (to this offset) */
  172.     u_long        wa_count;    /* size of this write */
  173.     char        *wa_data;    /* data to write (up to NFS_MAXDATA) */
  174.     char        *wa_hook;    /* hook for optimizations, not xdr'd */
  175. };
  176.  
  177.  
  178. /*
  179.  * File attributes
  180.  */
  181. struct nfsfattr {
  182.     enum nfsftype    na_type;    /* file type */
  183.     u_long        na_mode;    /* protection mode bits */
  184.     u_long        na_nlink;    /* # hard links */
  185.     u_long        na_uid;        /* owner user id */
  186.     u_long        na_gid;        /* owner group id */
  187.     u_long        na_size;    /* file size in bytes */
  188.     u_long        na_blocksize;    /* prefered block size */
  189.     u_long        na_rdev;    /* special device # */
  190.     u_long        na_blocks;    /* Kb of disk used by file */
  191.     u_long        na_fsid;    /* device # */
  192.     u_long        na_nodeid;    /* inode # */
  193.     struct timeval    na_atime;    /* time of last access */
  194.     struct timeval    na_mtime;    /* time of last modification */
  195.     struct timeval    na_ctime;    /* time of last change */
  196. };
  197.  
  198. #ifdef _KERNEL
  199. #define n2v_type(x)    (NA_ISFIFO(x) ? VFIFO : ntype_to_vtype(((x)->na_type)))
  200.  
  201. extern enum nfsftype    vtype_to_ntype(u_short);
  202. extern u_short        ntype_to_vtype(enum nfsftype);
  203. #endif
  204. #define n2v_rdev(x)    (NA_ISFIFO(x) ? 0 : (x)->na_rdev)
  205.  
  206. /*
  207.  * Arguments to remote read
  208.  */
  209. struct nfsreadargs {
  210.     fhandle_t    ra_fhandle;    /* handle for file */
  211.     u_long        ra_offset;    /* byte offset in file */
  212.     u_long        ra_count;    /* immediate read count */
  213.     u_long        ra_totcount;    /* total read cnt (from this offset) */
  214. };
  215.  
  216. /*
  217.  * Status OK portion of remote read reply
  218.  */
  219. struct nfsrrok {
  220.     struct nfsfattr    rrok_attr;    /* attributes, need for pagin */
  221.     u_long        rrok_count;    /* bytes of data */
  222.     char        *rrok_data;    /* data (up to NFS_MAXDATA bytes) */
  223.     struct buf    *rrok_bp;    /* buffer pointer for bread */
  224.     u_long        rrok_bsize;    /* buffer memory size */
  225.     struct vnode    *rrok_vp;    /* vnode assoc. with mapping */
  226. };
  227.  
  228. /*
  229.  * Reply from remote read
  230.  */
  231. struct nfsrdresult {
  232.     enum nfsstat    rr_status;        /* status of read */
  233.     union {
  234.         struct nfsrrok    rr_ok_u;    /* attributes, need for pagin */
  235.     } rr_u;
  236. };
  237. #define    rr_ok        rr_u.rr_ok_u
  238. #define    rr_attr        rr_u.rr_ok_u.rrok_attr
  239. #define    rr_count    rr_u.rr_ok_u.rrok_count
  240. #define    rr_data        rr_u.rr_ok_u.rrok_data
  241. #define rr_bp        rr_u.rr_ok_u.rrok_bp
  242. #define    rr_bsize    rr_u.rr_ok_u.rrok_bsize
  243. #define rr_vp        rr_u.rr_ok_u.rrok_vp
  244.  
  245.  
  246. /*
  247.  * File attributes which can be set
  248.  */
  249. struct nfssattr {
  250.     u_long        sa_mode;    /* protection mode bits */
  251.     u_long        sa_uid;        /* owner user id */
  252.     u_long        sa_gid;        /* owner group id */
  253.     u_long        sa_size;    /* file size in bytes */
  254.     struct timeval    sa_atime;    /* time of last access */
  255.     struct timeval    sa_mtime;    /* time of last modification */
  256. };
  257.  
  258.  
  259. /*
  260.  * Reply status with file attributes
  261.  */
  262. struct nfsattrstat {
  263.     enum nfsstat    ns_status;        /* reply status */
  264.     union {
  265.         struct nfsfattr ns_attr_u;    /* NFS_OK: file attributes */
  266.     } ns_u;
  267. };
  268. #define    ns_attr    ns_u.ns_attr_u
  269.  
  270.  
  271. /*
  272.  * NFS_OK part of read sym link reply union
  273.  */
  274. struct nfssrok {
  275.     u_long    srok_count;    /* size of string */
  276.     char    *srok_data;    /* string (up to NFS_MAXPATHLEN bytes) */
  277. };
  278.  
  279. /*
  280.  * Result of reading symbolic link
  281.  */
  282. struct nfsrdlnres {
  283.     enum nfsstat    rl_status;        /* status of symlink read */
  284.     union {
  285.         struct nfssrok    rl_srok_u;    /* name of linked to */
  286.     } rl_u;
  287. };
  288. #define    rl_srok        rl_u.rl_srok_u
  289. #define    rl_count    rl_u.rl_srok_u.srok_count
  290. #define    rl_data        rl_u.rl_srok_u.srok_data
  291.  
  292.  
  293. /*
  294.  * Arguments to readdir
  295.  */
  296. struct nfsrddirargs {
  297.     fhandle_t rda_fh;    /* directory handle */
  298.     u_long rda_offset;    /* offset in directory (opaque) */
  299.     u_long rda_count;    /* number of directory bytes to read */
  300. };
  301.  
  302. /*
  303.  * NFS_OK part of readdir result
  304.  */
  305. struct nfsrdok {
  306.     u_long    rdok_offset;        /* next offset (opaque) */
  307.     u_long    rdok_size;        /* size in bytes of entries */
  308.     bool_t    rdok_eof;        /* true if last entry is in result */
  309.     struct dirent *rdok_entries;    /* variable number of entries */
  310.     struct buf *rdok_bp;        /* buffer containing entries */
  311. };
  312.  
  313. /*
  314.  * Readdir result
  315.  */
  316. struct nfsrddirres {
  317.     u_long        rd_bufsize;    /* client request size (not xdr'ed) */
  318.     enum nfsstat    rd_status;
  319.     union {
  320.         struct nfsrdok rd_rdok_u;
  321.     } rd_u;
  322. };
  323. #define    rd_rdok        rd_u.rd_rdok_u
  324. #define    rd_offset    rd_u.rd_rdok_u.rdok_offset
  325. #define    rd_size        rd_u.rd_rdok_u.rdok_size
  326. #define    rd_eof        rd_u.rd_rdok_u.rdok_eof
  327. #define    rd_entries    rd_u.rd_rdok_u.rdok_entries
  328.  
  329.  
  330. /*
  331.  * Arguments for directory operations
  332.  */
  333. struct nfsdiropargs {
  334.     fhandle_t    da_fhandle;    /* directory file handle */
  335.     char        *da_name;    /* name (up to NFS_MAXNAMLEN bytes) */
  336. };
  337.  
  338. /*
  339.  * NFS_OK part of directory operation result
  340.  */
  341. struct  nfsdrok {
  342.     fhandle_t    drok_fhandle;    /* result file handle */
  343.     struct nfsfattr    drok_attr;    /* result file attributes */
  344. };
  345.  
  346. /*
  347.  * Results from directory operation
  348.  */
  349. struct  nfsdiropres {
  350.     enum nfsstat    dr_status;    /* result status */
  351.     union {
  352.         struct  nfsdrok    dr_drok_u;    /* NFS_OK result */
  353.     } dr_u;
  354. };
  355. #define    dr_drok        dr_u.dr_drok_u
  356. #define    dr_fhandle    dr_u.dr_drok_u.drok_fhandle
  357. #define    dr_attr        dr_u.dr_drok_u.drok_attr
  358.  
  359. /*
  360.  * arguments to setattr
  361.  */
  362. struct nfssaargs {
  363.     fhandle_t    saa_fh;        /* fhandle of file to be set */
  364.     struct nfssattr    saa_sa;        /* new attributes */
  365. };
  366.  
  367. /*
  368.  * arguments to create and mkdir
  369.  */
  370. struct nfscreatargs {
  371.     struct nfsdiropargs    ca_da;    /* file name to create and parent dir */
  372.     struct nfssattr        ca_sa;    /* initial attributes */
  373. };
  374.  
  375. /*
  376.  * arguments to link
  377.  */
  378. struct nfslinkargs {
  379.     fhandle_t        la_from;    /* old file */
  380.     struct nfsdiropargs    la_to;        /* new file and parent dir */
  381. };
  382.  
  383. /*
  384.  * arguments to rename
  385.  */
  386. struct nfsrnmargs {
  387.     struct nfsdiropargs rna_from;    /* old file and parent dir */
  388.     struct nfsdiropargs rna_to;    /* new file and parent dir */
  389. };
  390.  
  391. /*
  392.  * arguments to symlink
  393.  */
  394. struct nfsslargs {
  395.     struct nfsdiropargs    sla_from;    /* old file and parent dir */
  396.     char            *sla_tnm;    /* new name */
  397.     struct nfssattr        sla_sa;        /* attributes */
  398. };
  399.  
  400. /*
  401.  * NFS_OK part of statfs operation
  402.  */
  403. struct nfsstatfsok {
  404.     u_long fsok_tsize;    /* preferred transfer size in bytes */
  405.     u_long fsok_bsize;    /* fundamental file system block size */
  406.     u_long fsok_blocks;    /* total blocks in file system */
  407.     u_long fsok_bfree;    /* free blocks in fs */
  408.     u_long fsok_bavail;    /* free blocks avail to non-superuser */
  409. };
  410.  
  411. /*
  412.  * Results of statfs operation
  413.  */
  414. struct nfsstatfs {
  415.     enum nfsstat    fs_status;    /* result status */
  416.     union {
  417.         struct    nfsstatfsok fs_fsok_u;    /* NFS_OK result */
  418.     } fs_u;
  419. };
  420. #define    fs_fsok        fs_u.fs_fsok_u
  421. #define    fs_tsize    fs_u.fs_fsok_u.fsok_tsize
  422. #define    fs_bsize    fs_u.fs_fsok_u.fsok_bsize
  423. #define    fs_blocks    fs_u.fs_fsok_u.fsok_blocks
  424. #define    fs_bfree    fs_u.fs_fsok_u.fsok_bfree
  425. #define    fs_bavail    fs_u.fs_fsok_u.fsok_bavail
  426.  
  427. /*
  428.  * XDR routines for handling structures defined above
  429.  */
  430. #ifdef _KERNEL
  431. extern bool_t xdr_attrstat(struct __xdr_s *, struct nfsattrstat *);
  432. extern bool_t xdr_creatargs(struct __xdr_s *, struct nfscreatargs *);
  433. extern bool_t xdr_diropargs(struct __xdr_s *, struct nfsdiropargs *);
  434. extern bool_t xdr_diropres(struct __xdr_s *, struct nfsdiropres *);
  435. extern bool_t xdr_drok(struct __xdr_s *, struct nfsdrok *);
  436. extern bool_t xdr_fattr(struct __xdr_s *, struct nfsfattr *);
  437. extern bool_t xdr_fhandle(struct __xdr_s *, fhandle_t *);
  438. extern bool_t xdr_fsok(struct __xdr_s *, struct nfsstatfsok *);
  439. extern bool_t xdr_linkargs(struct __xdr_s *, struct nfslinkargs *);
  440. extern bool_t xdr_rddirargs(struct __xdr_s *, struct nfsrddirargs *);
  441. extern bool_t xdr_putrddirres(struct __xdr_s *, struct nfsrddirres *);
  442. extern bool_t xdr_getrddirres(struct __xdr_s *, struct nfsrddirres *);
  443. extern bool_t xdr_rdlnres(struct __xdr_s *, struct nfsrdlnres *);
  444. extern bool_t xdr_rdresult(struct __xdr_s *, struct nfsrdresult *);
  445. extern bool_t xdr_readargs(struct __xdr_s *, struct nfsreadargs *);
  446. extern bool_t xdr_rnmargs(struct __xdr_s *, struct nfsrnmargs *);
  447. extern bool_t xdr_rrok(struct __xdr_s *, struct nfsrrok *);
  448. extern bool_t xdr_saargs(struct __xdr_s *, struct nfssaargs *);
  449. extern bool_t xdr_sattr(struct __xdr_s *, struct nfssattr *);
  450. extern bool_t xdr_slargs(struct __xdr_s *, struct nfsslargs *);
  451. extern bool_t xdr_srok(struct __xdr_s *, struct nfssrok *);
  452. extern bool_t xdr_timeval(struct __xdr_s *, struct timeval *);
  453. extern bool_t xdr_writeargs(struct __xdr_s *, struct nfswriteargs *);
  454. extern bool_t xdr_statfs(struct __xdr_s *, struct nfsstatfs *);
  455. #endif
  456.  
  457. /*
  458.  * Remote file service routines
  459.  */
  460. #define    RFS_NULL    0
  461. #define    RFS_GETATTR    1
  462. #define    RFS_SETATTR    2
  463. #define    RFS_ROOT    3
  464. #define    RFS_LOOKUP    4
  465. #define    RFS_READLINK    5
  466. #define    RFS_READ    6
  467. #define    RFS_WRITECACHE    7
  468. #define    RFS_WRITE    8
  469. #define    RFS_CREATE    9
  470. #define    RFS_REMOVE    10
  471. #define    RFS_RENAME    11
  472. #define    RFS_LINK    12
  473. #define    RFS_SYMLINK    13
  474. #define    RFS_MKDIR    14
  475. #define    RFS_RMDIR    15
  476. #define    RFS_READDIR    16
  477. #define    RFS_STATFS    17
  478. #define    RFS_NPROC    18
  479.  
  480. /*
  481.  * remote file service numbers
  482.  */
  483. #define    NFS_PROGRAM    ((u_long)100003)
  484. #define    NFS_VERSION    ((u_long)2)
  485. #define    NFS_PORT    2049
  486.  
  487. #endif /* !__NFS_HEADER__ */
  488.